<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of welcome
 *
 * @author Obi
 */
class Admin_sellshare extends MY_Controller {

    function __construct() {
        parent::__construct();
        
        $cek_admin = $this->session->userdata('cek_admin');
        if (!$cek_admin)
            redirect("admin");

        $this->msellshare = new M_sellshare();
    }

    function index() {

        $data['title'] = 'Data Share';

        $data['list'] = $this->msellshare->select_data();
        $data['sellshare'] = $this->msellshare->get();

        $data['isi'] = 'isi';
        $this->load->view('template_admin', $data);
    }

    function tambah() {

        $data['title'] = 'sell Share';

        $data['id'] = "";
        $data['securities_list'] = $this->msellshare->select_data();
        $data['stock_list'] = $this->msellshare->select_data_stock();
		$data['tanggal'] = "";
        $data['securities'] = "";
        $data['stock'] = "";
        $data['qty'] = "0";
        $data['price'] = "0";
        $data['note'] = "";
        $data['status'] = "0";
		
        $data['isi'] = 'form';
        $this->load->view('template_admin', $data);
    }

    function edit($id = NULL) {

        $data['title'] = 'Preview And Process';

        $dt = $this->msellshare->where("orderno = '$id'")->get();

        $data['id'] = $dt->orderno;
		$data['securities_list'] = $this->msellshare->select_data();
        $data['stock_list'] = $this->msellshare->select_data_stock();
        $data['tanggal'] = $dt->trandate;
        $data['securities'] = $dt->security_code;
        $data['stock'] = $dt->symbol;
        $data['qty'] = $dt->quantity;
        $data['price'] = $dt->price;
        $data['note'] = $dt->note;
        $data['status'] = "1";

        $data['isi'] = 'form';
        $this->load->view('template_admin', $data);
    }

    function delete($id) {
        $this->msellshare->delete($id);
        redirect("admin_sellshare");
    }

    function simpan() {
        $id = $this->input->post('id');

        $data = array(
            'security_code' => $this->input->post('securities'),
            'symbol' => $this->input->post('stock'),
            'trandate' => $this->input->post('tanggal'),
            'duedate' => $this->input->post('tanggal'),
            'quantity' => $this->input->post('qty'),
            'price' => $this->input->post('price'),
            'note' => $this->input->post('note'),
            'status' => $this->input->post('status')
        );

        if ($id == "") {
            $this->msellshare->insert($data);
        } else {
            $this->msellshare->update($data, $id);
        }

        redirect("admin_sellshare");
    }

}

?>
